"""
角色相关的Pydantic模型
"""
from typing import List, Optional
from pydantic import BaseModel, Field
from datetime import datetime
from app.models.role import RoleScope


class RoleBase(BaseModel):
    """角色基础模型"""
    name: str = Field(..., description="角色名称", max_length=100)
    code: str = Field(..., description="角色代码", max_length=50)
    scope: RoleScope = Field(..., description="角色作用域")
    description: Optional[str] = Field(None, description="角色描述")
    permissions: Optional[List[str]] = Field(default_factory=list, description="权限列表")
    is_default: bool = Field(False, description="是否为默认角色")
    is_active: bool = Field(True, description="是否激活")


class RoleCreate(RoleBase):
    """创建角色模型"""
    pass


class RoleUpdate(BaseModel):
    """更新角色模型"""
    name: Optional[str] = Field(None, description="角色名称", max_length=100)
    code: Optional[str] = Field(None, description="角色代码", max_length=50)
    scope: Optional[RoleScope] = Field(None, description="角色作用域")
    description: Optional[str] = Field(None, description="角色描述")
    permissions: Optional[List[str]] = Field(None, description="权限列表")
    is_active: Optional[bool] = Field(None, description="是否激活")


class RoleResponse(BaseModel):
    """角色响应模型"""
    id: str = Field(..., description="角色ID")
    name: str = Field(..., description="角色名称", max_length=100)
    code: str = Field(..., description="角色代码", max_length=50)
    scope: RoleScope = Field(default=RoleScope.PROJECT, description="角色作用域")
    description: Optional[str] = Field(None, description="角色描述")
    permissions: Optional[List[str]] = Field(default_factory=list, description="权限列表")
    is_default: bool = Field(False, description="是否为默认角色")
    is_active: bool = Field(True, description="是否激活")
    is_system: bool = Field(False, description="是否为系统角色")
    created_at: Optional[datetime] = Field(None, description="创建时间")
    updated_at: Optional[datetime] = Field(None, description="更新时间")
    
    class Config:
        from_attributes = True


class RoleListResponse(BaseModel):
    """角色列表响应模型"""
    roles: List[RoleResponse]
    total: int
    page: int
    size: int